package me.lc;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class PageControlView extends LinearLayout {

	private int count;

	private Context context;

	public void setCount(int count) {
		this.count = count;
	}

	public PageControlView(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.init(context);
	}

	public PageControlView(Context context) {
		super(context);
		this.init(context);
	}

	private void init(Context context) {
		this.context = context;
	}

	public void callback(int currentIndex) {
		generatePageControl(currentIndex);
	}

	public void generatePageControl(final int currentIndex) {

		FunPeaceActivity.Instance.runOnUiThread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				Log.d("PageControlView", "currentIndex" + currentIndex + "");
				PageControlView.this.removeAllViews();

				for (int i = 0; i < PageControlView.this.count; i++) {
					ImageView imageView = new ImageView(context);
					LayoutParams params = generateDefaultLayoutParams();
					params.rightMargin = 5;
					params.leftMargin = 5;
					imageView.setLayoutParams(params);
					if (currentIndex == i) {
						imageView.setImageResource(R.drawable.product_point_b);
					} else {
						imageView.setImageResource(R.drawable.product_point_a);
					}
					PageControlView.this.addView(imageView);
				}
			}
		});

	}
}
